package com.zhicheng.controller;

import com.zhicheng.pojo.Order;
import com.zhicheng.pojo.dto.CreOrderDTO;
import com.zhicheng.pojo.result.PageResult;
import com.zhicheng.pojo.result.Result;
import com.zhicheng.pojo.vo.OrderVO;
import com.zhicheng.pojo.vo.PreOrderVO;
import com.zhicheng.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Api(tags = "订单相关接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/order/pre")
    @ApiOperation("订单结算页")
    public Result<PreOrderVO> preOrder(){
        PreOrderVO preOrderVO = orderService.preOrder();
        return Result.success(preOrderVO);
    }

    @PostMapping("/order")
    @ApiOperation("生成订单")
    public Result creOrder(@RequestBody CreOrderDTO creOrderDTO){
        Order order = orderService.creOrder(creOrderDTO);
        return Result.success(order);
    }

    @GetMapping("/order/{id}")
    @ApiOperation("根据id查询订单")
    public Result<Order> getByOrderId(@PathVariable String id){
        Order order = orderService.getByOrderId(id);
        return Result.success(order);
    }

    @GetMapping("/member/order")
    @ApiOperation("根据用户id分页查询订单")
    public Result<PageResult<OrderVO>> getByUserId(Integer orderStatus, int page, int pageSize){
        PageResult<OrderVO> pageResult = orderService.getByUserId(orderStatus,page,pageSize);
        return Result.success(pageResult);
    }


}
